package d9_com.itheima.Date_jdk8;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class Test3_LocalDateTime {
    public static void main(String[] args) {
        //0、获取本地日期和时间对象
        LocalDateTime id = LocalDateTime.now();//时 分 秒 纳秒
        System.out.println(id);

        //1、获取日期和时间的全部信息
        int year = id.getYear();//年
        int month = id.getMonthValue();//月(1-12)
        int day = id.getDayOfMonth();//日
        int dayofYear = id.getDayOfYear();// 一年中的第几天
        int dayofWeek = id.getDayOfWeek().getValue();//星期几
        int hour = id.getHour();//时
        int minute = id.getMinute();//分
        int second = id.getSecond();//秒
        int nano = id.getNano();//纳秒

        //2、直接修改日期和时间:
        // withYear、withMonth、withDayOfMonth、withDayofYear
        // withHour、withMinute、withSecond、withNano
        LocalDateTime id1 = id.withYear(2099);
        LocalDateTime id2 = id.withMonth(12);
        LocalDateTime id3 = id.withDayOfMonth(12);
        LocalDateTime id4 = id.withDayOfYear(12);
        LocalDateTime id5 = id.withHour(10);
        LocalDateTime id6 = id.withMinute(10);
        LocalDateTime id7 = id.withSecond(10);
        LocalDateTime id8 = id.withNano(10);

        //3、加多少:
        // plusYears、plusMonths、plusDays、plusWeeks
        // plusHours、plusMinutes、plusSeconds、plusNanos
        LocalDateTime id9 = id.plusYears(2);
        LocalDateTime ld10 = id.plusMonths(2);
        LocalDateTime ld11 = id.plusDays(2);
        LocalDateTime ld12 = id.plusWeeks(2);
        LocalDateTime id13 = id.plusHours(2);
        LocalDateTime id14 = id.plusMinutes(2);
        LocalDateTime id15 = id.plusSeconds(2);
        LocalDateTime id16 = id.plusNanos(2);

        //4、减多少:
        // minusYears、minusMonths、minusDays、minusWeeks
        // minusHours、minusMinutes、minusSeconds、minusNanos
        LocalDateTime id17 = id.minusYears(2);
        LocalDateTime id18 = id.minusMonths(2);
        LocalDateTime id19 = id.minusDays(2);
        LocalDateTime id20 = id.minusWeeks(2);
        LocalDateTime id21 = id.minusHours(2);
        LocalDateTime id22 = id.minusMinutes(2);
        LocalDateTime id23 = id.minusSeconds(2);
        LocalDateTime id24 = id.minusNanos(2);

        //5、获取指定时间的LocalTime对象:
        // public static LocalTime of(int hour int minute int second)
        LocalDateTime id25 = LocalDateTime.of(2024, 12, 12, 12, 12, 12, 12);
        LocalDateTime id26 = LocalDateTime.of(2024, 12, 12, 12, 12, 12, 12);

        //6、判断2个时间，是否相等，在前还是在后:equals isBefore isAfter
        System.out.println(id25.equals(id26));//true
        System.out.println(id25.isAfter(id));//true
        System.out.println(id25.isBefore(id)); //false

        //7、可以把LocalDateTime转换成LocalDate和LocaLTime
        // public LocalDate toLocalDate()
        // public LocalTime toLocalTime()
        // public static LocalDateTime of(LocalDate date, LocalTime time)
        LocalDate d = id.toLocalDate();
        LocalTime t = id.toLocalTime();
        LocalDateTime dt = LocalDateTime.of(d, t);
    }
}
